﻿using System;
using System.Windows.Data;

namespace Ags.MonsterTools.Guids
{
    public class StringToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
                return Binding.DoNothing;
            return value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int result;
            if (int.TryParse(value as string, out result))
                return result;
            else
            {
                return Binding.DoNothing;
            }
        }
    }
}
